package org.vectrics.common.view;

import org.apache.ecs.html.Div;
import org.apache.ecs.html.Input;
import org.vectrics.common.html.Row;
import org.vectrics.common.html.TextHelper;

public class HtmlFormMonthYearRow extends HtmlFormRow {
	private String monthParamName = null;
	private String yearParamName = null;
	
	public HtmlFormMonthYearRow(HtmlForm form, String paramName,
			boolean required) {
		super(form, paramName, required);
		this.monthParamName = paramName  + "_month";
		this.yearParamName = yearParamName + "_year";

		Div valueDiv = this.getValueDiv();
        Input editBox = makeEdit(this.monthParamName);
        editBox.setClass("formDateFieldClass");
        String month = this.getHtmlForm().getParameterValue(monthParamName);
        while (month.length() < 2) {
        	month = "0" + month;
        }
        editBox.setValue(month);
        valueDiv.addElement(editBox);
        
        
        valueDiv.addElement("&nbsp;:&nbsp;");
        editBox = makeEdit(this.yearParamName);
        String years = this.getHtmlForm().getParameterValue(yearParamName);
        while (years.length() < 2) {
        	years = "0" + years;
        }
        editBox.setValue(years);
        editBox.setClass("formDateFieldClass");
        valueDiv.addElement(editBox);
        
    	this.getHtmlForm().setFocusElementIfNull(this.monthParamName);
	}
	
}
